﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MDS
{
    /// <summary>
    /// 证券类别
    /// </summary>
    public class StkType:EnumBase<string>
    {
        private static Dictionary<string, StkType> _allStkTypes;
        private StkType(string id):base(id) {  }
        static StkType()
        {
            Equity = new StkType("A0");
            Bond = new StkType("A1");
            Fund = new StkType("A2");
            OTCFund = new StkType("A3");
            ETF = new StkType("A4");
            Warrant = new StkType("A5");
            Repo = new StkType("A6");
            Index = new StkType("A8");
            _allStkTypes = new Dictionary<string, StkType>();
            _allStkTypes.Add(Equity._value, Equity);
            _allStkTypes.Add(Bond._value, Bond);
            _allStkTypes.Add(Fund._value, Fund);
            _allStkTypes.Add(OTCFund._value, OTCFund);
            _allStkTypes.Add(ETF._value, ETF);
            _allStkTypes.Add(Warrant._value, Warrant);
            _allStkTypes.Add(Repo._value, Repo);
            _allStkTypes.Add(Index._value, Index);
        }

        public static bool TryParse(string stkTypeStr, out StkType stkType)
        {
            if (_allStkTypes.ContainsKey(stkTypeStr))
            {
                stkType = _allStkTypes[stkTypeStr];
                return true;
            }
            else
            {
                stkType = default(StkType);
                return false;
            }
        }
        public static implicit operator StkType(string stkTypeStr)
        {
            StkType rtn;
            TryParse(stkTypeStr, out rtn);
            return rtn;
        }
        
        /// <summary>
        /// 股票
        /// </summary>
        public static StkType Equity { get; private set; }
        /// <summary>
        /// 债券
        /// </summary>
        public static StkType Bond { get; private set; }
        /// <summary>
        /// 场内基金
        /// </summary>
        public static StkType Fund { get; private set; }
        /// <summary>
        /// 开放基金
        /// </summary>
        public static StkType OTCFund { get; private set; }
        /// <summary>
        /// ETF基金
        /// </summary>
        public static StkType ETF { get; private set; }
        /// <summary>
        /// 权证
        /// </summary>
        public static StkType Warrant { get; private set; }
        /// <summary>
        /// 回购
        /// </summary>
        public static StkType Repo { get; private set; }
        /// <summary>
        /// 指数
        /// </summary>
        public static StkType Index { get; private set; }

    }
}
